package com.heima.article.config;

import com.heima.article.service.ApArticleConfigService;
import com.alibaba.fastjson.JSON;
import freemarker.template.TemplateException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;


@Component
public class OnMessageApArticleListener {
    @Autowired
    private ApArticleConfigService apArticleConfigService;


    @KafkaListener(topics = "DownOrUp-topic")
    public void onMessage(String message) throws TemplateException, IOException {
        if (!StringUtils.isEmpty(message)) {
            System.err.println(message);
            Map map = JSON.parseObject(message, Map.class);
            apArticleConfigService.updateByMap(map);

        }
    }

}
